<?php    
    $now = time();
    $minus365days = strtotime("-365 days",$now);
    
    # Käyttäjän painoyksikkö
    $unit = arrGet(API::userLoad(),"default_unit","kg");
?>

<style type="text/css">
    .onerepmax-label-unit {
        font-weight: normal;
    }
</style>

<div class="row">
    <div class="col-sm-2">
        <label for="onerepmax-input-startdate">
            From
        </label>
    </div>
    <div class="col-sm-10">
        <div class="input-group date form_date" data-date-format="yyyy-mm-dd">
            <?php
                FT::input("startdate",date("Y-m-d",$minus365days),array(
                    "class"     => "form-control",
                    "id"        => "onerepmax-input-startdate",
                    "maxlength" => 10,
                    "readonly"  => "readonly"
                ));
            ?>
            <span class="input-group-addon">
                <span class="glyphicon glyphicon-th"></span>
            </span>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-sm-2">
        <label for="onerepmax-input-enddate">
            To
        </label>
    </div>
    <div class="col-sm-10">
        <div class="input-group date form_date" data-date-format="yyyy-mm-dd">
            <?php
                FT::input("enddate",date("Y-m-d",$now),array(
                    "class"     => "form-control",
                    "id"        => "onerepmax-input-enddate",
                    "maxlength" => 10,
                    "readonly"  => "readonly"
                ));
            ?>
            <span class="input-group-addon">
                <span class="glyphicon glyphicon-th"></span>
            </span>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-sm-2">
        <label for="onerepmax-select-exercisecategory">
            Exercise
        </label>
    </div>
    <div class="col-sm-10">
        <?php
            FT::select(null,null,array(
                "class" => "form-control",
                "id"    => "onerepmax-select-exercisecategory"
            ));
        ?>
    </div>
</div>

<div class="row">
    <div class="col-sm-2">
        <label for="onerepmax-select-exerciseid">
            &nbsp;
        </label>
    </div>
    <div class="col-sm-10">
        <?php
            FT::select("exerciseid",null,array(
                "class" => "form-control",
                "id"    => "onerepmax-select-exerciseid"
            ));
        ?>
    </div>
</div>

<div class="row">
    <div class="col-sm-2">
        <label for="onerepmax-select-reptype">
            Rep type
        </label>
    </div>
    <div class="col-sm-10">
        <?php
            $reptypes = array_merge(
                array("" => "- Not selected -"),
                getRepetitionsTypeArr()
            );
            FT::select("reptype",$reptypes,array(
                "class" => "form-control",
                "id"    => "onerepmax-select-reptype"
            ));
        ?>
    </div>
</div>

<div class="row">
    <div class="col-sm-2">
        <label>
            Unit
        </label>
    </div>
    <div class="col-sm-10">
        <label class="onerepmax-label-unit">
            <?php
                FT::radio("unit","kg",null,$unit);
            ?>
            KG
        </label>
        &nbsp;
        <label class="onerepmax-label-unit">
            <?php
                FT::radio("unit","lb",null,$unit);
            ?>
            LB
        </label>
    </div>
</div>

<div class="row">
    <div class="col-sm-2">
        &nbsp;
    </div>
    <div class="col-sm-10">
        <?php
            FT::button("Get",array(
                "class"     => "btn onerepmax-button btn-default",
                "id"        => "onerepmax-button-get",
                "disabled"  => "disabled"
            ));
        ?>
        &nbsp;
        <label>
            <?php
                FT::checkbox("calculated",1,array(
                    "checked"   => "checked",
                    "id"        => "onerepmax-input-calculated"
                ));
            ?>
            Include calculated
        </label>
    </div>
</div>

<div class="container" id="onerepmax-div-data"></div>

<script type="text/javascript">
    $(".form_date").datetimepicker({
        autoclose:      1,
        minView:        2,
        todayBtn:       1,		
        todayHighlight: 1,
        weekStart:      1
    });
    
    // Alusta harjoitteiden alasvetovalikot
    var categories  = ExerciseControl.getExerciseCategories();
    var cat         = Object.keys(categories)[0];
    var arr         = Object.keys(categories[cat])[0].split("|");
    var exercises   = ExerciseControl.getCategoryExercises(arr[0],arr[1]);
    
    $("#onerepmax-select-exercisecategory").
        html(FT.options(categories));
    
    $("#onerepmax-select-exerciseid").
        html(FT.options(exercises)).
        prepend(
            $("<option>").
                attr("value","0").
                text("- Not selected -")
        );
        
    getViewScript("onerepmax",function(){
        viewOnerepmax.initializePage();
        viewOnerepmax.getData();
    });
</script>